home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / share / tod / setup.exe / allegdlg.c next >
Encoding:
C/C++ Source or Header  |  2000-10-11  |  5.3 KB  |  233 lines

  1. /**************************************\
  2. * ALLEGDLG.C                           *
  3. * Dialog control defprocs for Allegro  *
  4. * Copr. 1999 Damian Yerrick            *
  5. \**************************************/
  6.  
  7. #include <errno.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. #include "allegro.h"
  13.  
  14. /* dotted_rect:
  15.  *  Draws a dotted rectangle, for showing an object has the input focus.
  16.  *  By Shawn Hargreaves
  17.  */
  18. static void dotted_rect(int x1, int y1, int x2, int y2, int fg, int bg)
  19. {
  20.    int x = ((x1+y1) & 1) ? 1 : 0;
  21.    int c;
  22.  
  23.    for (c=x1; c<=x2; c++) {
  24.       putpixel(screen, c, y1, (((c+y1) & 1) == x) ? fg : bg);
  25.       putpixel(screen, c, y2, (((c+y2) & 1) == x) ? fg : bg);
  26.    }
  27.  
  28.    for (c=y1+1; c<y2; c++) {
  29.       putpixel(screen, x1, c, (((c+x1) & 1) == x) ? fg : bg);
  30.       putpixel(screen, x2, c, (((c+x2) & 1) == x) ? fg : bg);
  31.    }
  32. }
  33.  
  34.  
  35. /* d_check_proc:
  36.  *  Who needs C++ after all? This is derived from d_button_proc, 
  37.  *  but overrides the drawing routine to provide a check box.
  38.  *  Original by Shawn Hargreaves (Allegro 3.11)
  39.  *  Changes by Damian Yerrick as of 30 April 1999:
  40.  *    Moved checkbox to the left to make it look like a Mac
  41.  *    or MS Windows checkbox.
  42.  */
  43. int DY_check_proc(int msg, DIALOG *d, int c)
  44. {
  45.    int x;
  46.    int fg;
  47.  
  48.    if (msg==MSG_DRAW) {
  49.       fg = (d->flags & D_DISABLED) ? gui_mg_color : d->fg;
  50.       text_mode(d->bg);
  51.       gui_textout(screen, d->dp, d->x+d->h+3, d->y+(d->h-(text_height(font)-gui_font_baseline))/2, fg, FALSE);
  52.       x = d->x;
  53.       rectfill(screen, x+1, d->y+1, x+d->h-1, d->y+d->h-1, d->bg);
  54.       rect(screen, x, d->y, x+d->h, d->y+d->h, fg);
  55.       if (d->flags & D_SELECTED) {
  56.      line(screen, x, d->y, x+d->h, d->y+d->h, fg);
  57.      line(screen, x, d->y+d->h, x+d->h, d->y, fg); 
  58.       }
  59.       if (d->flags & D_GOTFOCUS)
  60.      dotted_rect(x+1, d->y+1, x+d->h-1, d->y+d->h-1, fg, d->bg);
  61.       return D_O_K;
  62.    } 
  63.  
  64.    return d_button_proc(msg, d, 0);
  65. }
  66.  
  67.  
  68. /* DY_bitmap_proc() ********************
  69.  * Displays the transparent bitmap in dp, scaled as necessary.
  70.  */
  71. int DY_bitmap_proc(int msg, DIALOG *d, int c)
  72. {
  73.   if(msg == MSG_DRAW)
  74.   {
  75.     BITMAP *bmp = (BITMAP *)(d->dp);
  76.  
  77.     if(bmp != NULL)
  78.     {
  79.       if(bmp->w == d->w && bmp->h == d->h)
  80.         draw_sprite(screen, bmp, d->x, d->y);
  81.       else
  82.         stretch_sprite(screen, bmp, d->x, d->y, d->w, d->h);
  83.     }
  84.   }
  85.  
  86.   return D_O_K;
  87. }
  88.  
  89.  
  90. /* DY_action_proc() ********************
  91.  * By Damian Yerrick
  92.  * Inherits from d_button_proc()
  93.  * Declare this control as D_EXIT in your dialog item list.
  94.  *
  95.  * When clicked, this button calls the function in dp2:
  96.  *   int foobar(DIALOG *d);
  97.  * Then it un-highlights the button and returns what the callback returned.
  98.  * (Most callbacks should return D_REDRAW.)
  99.  */
  100. int DY_action_proc(int msg, DIALOG *d, int c)
  101. {
  102.   int ret;
  103.  
  104.   /* call the parent object */
  105.   ret = d_button_proc(msg, d, c);
  106.  
  107.   /* trap the close return value and call the function */
  108.   if(ret == D_CLOSE)
  109.   {
  110.     int (*callback)(DIALOG *d);
  111.  
  112.     // redraw button without highlight
  113.     scare_mouse();
  114.     ret = d_button_proc(MSG_DRAW, d, c);
  115.     unscare_mouse();
  116.  
  117.     // call the callback function
  118.     callback = d->dp2;
  119.     if(callback != NULL)
  120.       ret |= (*callback)(d);
  121.   }
  122.  
  123.   /* otherwise just return */
  124.   return ret;
  125. }
  126.  
  127.  
  128. /* DY_idle_proc() **********************
  129.  * By Damian Yerrick
  130.  * When placed into a dialog box in Allegro 3.9.31 or later, this function
  131.  * plays nice with the scheduler.
  132.  */
  133. int DY_idle_proc(int msg, DIALOG *unused2, int unused3)
  134. {
  135.   if(msg == MSG_IDLE)
  136.     yield_timeslice();
  137.   return D_O_K;
  138. }
  139.  
  140.  
  141. /* DY_pass_proc() **********************
  142.  * By Damian Yerrick
  143.  * An editable text object that doesn't show the text.
  144.  * Useful for passwords.
  145.  */
  146. int DY_pass_proc(int msg, DIALOG *d, int c)
  147. {
  148.   int f, l, p, w, x, fg, b, scroll;
  149.   char buf[16];
  150.   char *s;
  151.  
  152.   s = d->dp;
  153.   l = ustrlen(s);
  154.   if (d->d2 > l) 
  155.     d->d2 = l;
  156.  
  157.   /* calculate maximal number of displayable characters */
  158.   if (d->d2 == l)
  159.   {
  160.     usetc(buf+usetc(buf, ' '), 0);
  161.     x = text_length(font, buf);
  162.   }
  163.   else
  164.     x = 0;
  165.  
  166.   b = 0;
  167.  
  168.   for (p=d->d2; p>=0; p--)
  169.   {
  170.     usetc(buf+usetc(buf, ugetat(s, p)), 0);
  171.     x += text_length(font, buf);
  172.     b++;
  173.     if (x > d->w) 
  174.       break;
  175.   }
  176.  
  177.   if (x <= d->w)
  178.   {
  179.     b = l; 
  180.     scroll = FALSE;
  181.   }
  182.   else
  183.   {
  184.     b--; 
  185.     scroll = TRUE;
  186.   }
  187.  
  188.   switch (msg)
  189.   {
  190.     case MSG_START:
  191.     case MSG_CLICK:
  192.     case MSG_WANTFOCUS:
  193.     case MSG_LOSTFOCUS:
  194.     case MSG_KEY:
  195.     case MSG_CHAR:
  196.     case MSG_UCHAR:
  197.       return d_edit_proc(msg, d, c);
  198.       break;
  199.  
  200.     case MSG_DRAW:
  201.       fg = (d->flags & D_DISABLED) ? gui_mg_color : d->fg;
  202.       x = 0;
  203.  
  204.       if (scroll)
  205.       {
  206.         p = d->d2-b+1; 
  207.         b = d->d2; 
  208.       }
  209.       else 
  210.         p = 0; 
  211.  
  212.       for (; p<=b; p++)
  213.       {
  214.         f = ugetat(s, p);
  215.         usetc(buf+usetc(buf, (f) ? '*' : ' '), 0);
  216.         w = text_length(font, buf);
  217.         if (x+w > d->w) 
  218.           break;
  219.         f = ((p == d->d2) && (d->flags & D_GOTFOCUS));
  220.         text_mode((f) ? fg : d->bg);
  221.         textout(screen, font, buf, d->x+x, d->y, (f) ? d->bg : fg);
  222.         x += w;
  223.       }
  224.       if (x < d->w)
  225.         rectfill(screen, d->x+x, d->y, d->x+d->w-1, d->y+text_height(font)-1, d->bg);
  226.       break;
  227.   }
  228.  
  229.   return D_O_K;
  230. }
  231.  
  232.  
  233.